package com.turnengine.client.global.game.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Game Version Serializer.
 */
public class GameVersionSerializer implements IGameVersionSerializer {

	@Override
	public IGameVersion readObject(IDataReader reader) throws IOException {

		// Read fields
		int id = reader.readInt();
		String name = reader.readString(true);
		int gameId = reader.readInt();

		// Create object
		IGameVersion object = new GameVersion();
		object.setId(id);
		object.setName(name);
		object.setGameId(gameId);
		return object;
	}

	public void writeObject(IDataWriter writer, IGameVersion object) throws IOException {

		// Get fields
		int id = object.getId();
		String name = object.getName();
		int gameId = object.getGameId();

		// Write fields
		writer.writeInt(id);
		writer.writeString(name, true);
		writer.writeInt(gameId);
	}
}
